//
//  MyViewController.m
//  掌厨
//
//  Created by aoyolo on 15/10/22.
//  Copyright (c) 2015年 李祖铜. All rights reserved.
//

#import "MyViewController.h"

#import "LocalCell.h"

static CGFloat HeadimgHight = 250;

@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate>
{
    UIButton *userBtn;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong)UIImageView *imgView;

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置我的导航栏图标
    [self configureButton];
    
    self.navigationController.navigationBar.barTintColor = appColor;
    //设置导航栏标题的字体颜色和大小
    self.navigationItem.title = @"我的";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15], NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    _imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -HeadimgHight, self.view.bounds.size.width , HeadimgHight)];
    [_imgView setImage:[UIImage imageNamed:@"myBackgroundImage.jpg"]];
    [_tableView addSubview:_imgView];
    
    _tableView.contentInset =UIEdgeInsetsMake(HeadimgHight, 0, 0, 0);
    
    userBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    userBtn.frame = CGRectMake(_imgView.center.x/2, -_imgView.frame.size.height+20, 80, 80);
    userBtn.layer.cornerRadius =80/2;
    [userBtn setBackgroundImage:[UIImage imageNamed:@"userHeadImage"] forState:UIControlStateNormal];
    [_tableView addSubview:userBtn];
    
    UIButton *btn = [[UIButton alloc]init];
    btn.frame = CGRectMake(_imgView.center.x/4, -_imgView.frame.size.height+140, 210, 35);
    [btn setTitle:@"登录下，让掌厨更懂你" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"guide"] forState:UIControlStateNormal];
    
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 190, 0, 0);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 30);//图片文字添加混编偏移调整
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_tableView addSubview:btn];
    
    UILabel *titelLabel = [[UILabel alloc]initWithFrame:CGRectMake(_imgView.center.x/1.8, -_imgView.frame.size.height+220, 200, 30)];
    titelLabel.text =@"本地视频";
    titelLabel.font=[UIFont systemFontOfSize:15];
    titelLabel.textColor = [UIColor whiteColor];
    
    [_tableView addSubview:titelLabel];
    
    
    
    
    [_tableView registerNib:[UINib nibWithNibName:@"LocalCell" bundle:nil] forCellReuseIdentifier:@"LocalCellId"];
    
    
    UIImageView *imgViedo = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/4, self.view.bounds.size.height/6, 80, 100)];
    [imgViedo setImage:[UIImage imageNamed:@"noVideo"]];
    [_tableView addSubview:imgViedo];
    
    
    UILabel *labelViedo = [[UILabel alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/5, self.view.bounds.size.height/3, 180, 80)];
    labelViedo.text = @"你还没有下载的视频";
    labelViedo.font=[UIFont systemFontOfSize:14];
    
    [_tableView addSubview:labelViedo];
    
    
    
}


-(void)configureButton
{
    UIButton *configureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    configureBtn.frame= CGRectMake(0, 0, 50, 35);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:configureBtn];
    [configureBtn setImage:[UIImage imageNamed:@"configure"] forState:UIControlStateNormal];
    [configureBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 1;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==1) {
        return 300;
    }
    return 0;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==1)
    {
        LocalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LocalCellId"];
        return cell;
    }
    return 0;
}




-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat yOffset = scrollView.contentOffset.y;
    CGFloat xOffset = (yOffset +HeadimgHight)/2;
    if(yOffset < -HeadimgHight) {
        CGRect f =self.imgView.frame;
        f.origin.y= yOffset ;
        f.size.height=  -yOffset;
        f.origin.x= xOffset;
        f.size.width=self.view.bounds.size.width + fabs(xOffset)*2;
    
        self.imgView.frame= f;
        scrollView.minimumZoomScale = 2.0;

    }
}












@end
